package com.jpf.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jpf.demo.Goods;
import com.jpf.service.GoodsService;
@WebServlet("/DeleteGoods.do")
public class DeleteGoods extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		GoodsService goodsService = new GoodsService();
		int gid =Integer.parseInt(request.getParameter("gid"));
		if(goodsService.deleteGoods(gid))
			response.sendRedirect("QueryGoods.do");  
		else
		response.sendRedirect("admin/error.jsp");
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	String goods = request.getParameter("delgoods");
	GoodsService goodsService = new GoodsService();
	String[] strs = goods.split(",");
	for (int i = 0; i < strs.length; i++) {
		try {
			int gid = Integer.parseInt(strs[i]);
			goodsService.deleteGoods(gid);
		} catch (Exception e) {
		}
	}
	}
}
